package com.lrd.snapshotorder.controller;

import com.lrd.snapshotorder.entity.SnapshotOrder;
import com.lrd.snapshotorder.protocol.ResultData;
import com.lrd.snapshotorder.protocol.dto.order.OrderTaskCreateDto;
import com.lrd.snapshotorder.protocol.dto.order.OrderTaskListDto;
import com.lrd.snapshotorder.protocol.dto.order.OrderTaskQueryDto;
import com.lrd.snapshotorder.protocol.dto.order.SnapshotOrderListDto;
import com.lrd.snapshotorder.protocol.dto.order.SnapshotOrderQueryDto;
import com.lrd.snapshotorder.service.OrderTaskService;
import com.lrd.snapshotorder.service.SnapshotOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单相关任务
 */
@RestController
@RequestMapping("/api/v1/snapshot/order")
public class SnapshotOrderController {

    @Autowired
    private SnapshotOrderService snapshotOrderService;
    @Autowired
    private OrderTaskService orderTaskService;

    /**
     * 生成订单任务
     *
     * @param orderTaskCreateDto
     * @return
     */
    @PostMapping("/createOrderTask")
    public ResultData<Boolean> createOrderTask(@RequestBody @Validated OrderTaskCreateDto orderTaskCreateDto) {

        return orderTaskService.createOrderTask(orderTaskCreateDto);
    }

    /**
     * @param queryDto 入参
     * @return
     */
    @PostMapping("/orderTaskList")
    public ResultData<List<OrderTaskListDto>> orderTaskList(@RequestBody OrderTaskQueryDto queryDto) {

        return orderTaskService.orderTaskList(queryDto);
    }

    /**
     * @param queryDto 入参
     * @return
     */
    @PostMapping("/snapshotOrderPageList")
    public ResultData<List<SnapshotOrderListDto>> snapshotOrderPageList(@RequestBody SnapshotOrderQueryDto queryDto) {

        return snapshotOrderService.snapshotOrderPageList(queryDto);
    }

    /**
     * @param queryDto 入参
     * @return
     */
    @PostMapping("/snapshotOrderAllList")
    public ResultData<List<SnapshotOrder>> snapshotOrderAllList(@RequestBody SnapshotOrderQueryDto queryDto) {

        return snapshotOrderService.snapshotOrderAllList(queryDto);
    }

    /**
     * 导出订单
     *
     * @param queryDto 入参
     * @return
     */
    @PostMapping("/exportOrder")
    public void exportOrder(@RequestBody SnapshotOrderQueryDto queryDto, HttpServletResponse response) throws Exception {
        snapshotOrderService.exportOrder(queryDto, response);
    }


    /**
     * 导出订单
     *
     * @return
     */
    @GetMapping("/exportOrderByBatchNumber")
    public void exportOrder(@RequestParam("batchNumber") Integer batchNumber, HttpServletResponse response) throws Exception {
        SnapshotOrderQueryDto queryDto = new SnapshotOrderQueryDto();
        queryDto.setBatchNumber(batchNumber);
        snapshotOrderService.exportOrder(queryDto, response);
    }

    /**
     * 导出订单使用
     *
     * @return
     */
    @GetMapping("/getOrderByBatchNumber")
    public List<SnapshotOrderListDto> getOrderByBatchNumber(@RequestParam("batchNumber") Integer batchNumber) {
        return snapshotOrderService.getOrderByBatchNumber(batchNumber);
    }
}
